package ink.sunflowerk.service.impl;

import ink.sunflowerk.dao.TeacherDao;
import ink.sunflowerk.exception.TeacherLoginException;
import ink.sunflowerk.pojo.Teacher;
import ink.sunflowerk.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhaokuii11@163.com
 * @create 2021-12-09 9:32
 * @Description
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherDao teacherDao;

    @Override
    public Teacher login(String username, String password) {
        Teacher teacher = teacherDao.getTeacher(username, password);
        if (teacher == null) {
            throw new TeacherLoginException("用户名或密码错误");
        }
        return teacher;
    }

    @Override
    public Teacher login(String phone) {
        Teacher teacher = teacherDao.getTeacher(phone);
        if (teacher == null) {
            throw new TeacherLoginException("手机号错误");
        }
        return teacher;
    }

    @Override
    public void register(Teacher teacher) {
        teacherDao.insertTeacher(teacher);
    }
}
